package cn.yj.common;

import cn.yj.commons.Status;
import cn.yj.tools.exception.ServiceException;
import com.fasterxml.jackson.annotation.JsonValue;
import javafx.beans.property.adapter.JavaBeanBooleanPropertyBuilder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <br>
 *
 * @author 永健
 * @since 2021-04-19 17:08
 */
public interface Enums extends Status {
    /**
     * 任务表相关枚举
     */
    static Map<String, String> STATUS_MAP_STR = new HashMap<>();
    static Map<String, TASK.STATUS> STATUS_MAP = new HashMap<>();
    static Map<String, Article.TYPE> ARTICLE_TYPE = new HashMap<>();

    class TASK {

        static void toMap() {
            STATUS[] values = STATUS.values();
            for (int i = 0; i < values.length; i++) {
                STATUS value = values[i];
                STATUS_MAP_STR.put(value.name(), value.msg);
                STATUS_MAP.put(value.name(), value);
            }
        }

        static {
            toMap();
        }

        public enum STATUS {
            // 包裹状态: 无人接单/已接单/处理中/完成/取消/超时
            no("待接单"), toAgree("待同意"), doing("进行中"), finish("已完成"), cancel("取消"), timeout("超时未接单");
            @JsonValue
            private String msg;

            STATUS(String msg) {
                this.msg = msg;
            }

            public static STATUS valueOfStatus(String status) {
                exits(status);
                return STATUS_MAP.get(status);
            }

            public static void exits(String status) {
                if (!STATUS_MAP.containsKey(status)) {
                    throw new ServiceException("任务状态异常：" + status);
                }
            }

            public static boolean equals(STATUS status, String statusStr) {
                if (status != null && status.name().equals(statusStr)) {
                    return true;
                }
                return false;
            }

            public String getMsg() {
                return msg;
            }

            public STATUS setMsg(String msg) {
                this.msg = msg;
                return this;
            }
        }

        public enum UrgentState {
            // 正常/紧急
            normal("正常"), urgent("紧急");

            @JsonValue
            private String msg;

            UrgentState(String msg) {
                this.msg = msg;
            }

            public static boolean equals(UrgentState status, String statusStr) {
                if (status != null && status.name().equals(statusStr)) {
                    return true;
                }
                return false;
            }

            public String getMsg() {
                return msg;
            }

            public UrgentState setMsg(String msg) {
                this.msg = msg;
                return this;
            }
        }
    }


    /**
     * 积分表相关枚举
     */
    class IntegralWater {
        public static boolean equals(IntegralWater.SOURCE source, String sourceStr) {
            if (source != null && source.name().equals(sourceStr)) {
                return true;
            }
            return false;
        }

        /**
         * 积分涞源
         */
        public enum SOURCE {
            REC_TASK("接收任务"), PUSH_ARTICLE("发布文章"), PUSH_TASK("发布任务"), REC_PACKAGE("接收包裹"), PUSH_PACKAGE("发布任务包裹"),
            SIGN_IN("每日签到"), SHARE("分享到朋"), KEEP_SIGN("连续签到"), REGISTER("完善资料"), INVITE("邀请朋友"), CASH_OUT("积分提现"),
            EXCHANGE("商品置换"), CANCEL_EXCHANGE("取消置换");

            @JsonValue
            private String msg;

            SOURCE(String msg) {
                this.msg = msg;
            }

            public String getMsg() {
                return msg;
            }

            public SOURCE setMsg(String msg) {
                this.msg = msg;
                return this;
            }
        }

        public enum TYPE {
            OUT("出账"), IN("进账");

            @JsonValue
            private String msg;


            TYPE(String msg) {
                this.msg = msg;
            }

            public String getMsg() {
                return msg;
            }

            public TYPE setMsg(String msg) {
                this.msg = msg;
                return this;
            }
        }

        public enum STATUS {
            submit("提交申请"), doing("处理中"), success("出账成功"), fail("提现失败");
            @JsonValue
            private String msg;

            STATUS(String msg) {
                this.msg = msg;
            }

            public String getMsg() {
                return msg;
            }

            public STATUS setMsg(String msg) {
                this.msg = msg;
                return this;
            }

        }
    }

    class Article {

        static {
            TYPE[] values = TYPE.values();
            for (TYPE type : values) {
                ARTICLE_TYPE.put(type.name(), type);
            }
        }

        public static void exits(String status) {
            if (!ARTICLE_TYPE.containsKey(status)) {
                throw new ServiceException("文章类型错误：" + status);
            }
        }

        public enum USER_VIEW_TYPE {
            VIEW("浏览量"), AGREE("点赞"), COMMENT_AGREE("评论点赞");
            @JsonValue
            private String msg;

            USER_VIEW_TYPE(String msg) {
                this.msg = msg;
            }

            public String getMsg() {
                return msg;
            }
        }

        public enum STATUS {
            DOING("审核中"), SUCCESS("成功"), FAIL("失败");
            @JsonValue
            private String msg;

            STATUS(String msg) {
                this.msg = msg;
            }

            public String getMsg() {
                return msg;
            }
        }

        public enum TYPE {
            PLAINTEXT("文字"), IMAGETEXT("图文"), VIDEOTEXT("视频");
            @JsonValue
            private String msg;

            TYPE(String msg) {
                this.msg = msg;
            }

            public String getMsg() {
                return msg;
            }

        }
    }

    class Common {
        public static final Integer ZERO = 0;
        public static final Integer ONE = 1;
        public static final Integer TRUE_V = 1;
        public static final Integer FALSE_V = 0;
        public static final boolean TRUE = true;
        public static final boolean FALSE = false;
    }

    class IntegralGood {
        public static Map<String, List<Map<String, Object>>> PROGRESS = new HashMap<>();
        private static List<NameValue> EXPRESS_STATUS_LIST = new ArrayList<>();

        static {
            List<Map<String, Object>> listSuccess = new ArrayList<>();
            List<Map<String, Object>> cancelSuccess = new ArrayList<>();
            Map<String, Object> init = new HashMap<>();
            Map<String, Object> handing = new HashMap<>();
            Map<String, Object> success = new HashMap<>();
            Map<String, Object> cancel = new HashMap<>();
            init.put("word", Enums.IntegralGood.EXPRESS_STATUS.NO_SEND.getMsg());
            init.put("status", Enums.IntegralGood.EXPRESS_STATUS.NO_SEND.name());
            init.put("isCurrentStatus", false);

            handing.put("word", Enums.IntegralGood.EXPRESS_STATUS.DOING.getMsg());
            handing.put("status", Enums.IntegralGood.EXPRESS_STATUS.DOING.name());
            handing.put("isCurrentStatus", false);

            success.put("word", Enums.IntegralGood.EXPRESS_STATUS.SEND_TO.getMsg());
            success.put("status", Enums.IntegralGood.EXPRESS_STATUS.SEND_TO.name());
            success.put("isCurrentStatus", false);

            cancel.put("word", Enums.IntegralGood.EXPRESS_STATUS.CANCEL.getMsg());
            cancel.put("status", Enums.IntegralGood.EXPRESS_STATUS.CANCEL.name());
            cancel.put("isCurrentStatus", false);

            listSuccess.add(init);
            listSuccess.add(handing);
            listSuccess.add(success);

            cancelSuccess.add(init);
            cancelSuccess.add(handing);
            cancelSuccess.add(cancel);
            PROGRESS.put(Enums.IntegralGood.EXPRESS_STATUS.SEND_TO.name(), listSuccess);
            PROGRESS.put(Enums.IntegralGood.EXPRESS_STATUS.DOING.name(), listSuccess);
            PROGRESS.put(Enums.IntegralGood.EXPRESS_STATUS.NO_SEND.name(), listSuccess);
            PROGRESS.put(Enums.IntegralGood.EXPRESS_STATUS.CANCEL.name(), cancelSuccess);
        }

        public enum STATUS {

            ON("上架"), OFF("下架");

            @JsonValue
            private String msg;

            STATUS(String msg) {
                this.msg = msg;
            }

            public String getMsg() {
                return msg;
            }

            public STATUS setMsg(String msg) {
                this.msg = msg;
                return this;
            }
        }

        public enum TYPE {
            ON("可用"), OFF("不可用");
            @JsonValue
            private String msg;

            TYPE(String msg) {
                this.msg = msg;
            }

            public String getMsg() {
                return msg;
            }

            public TYPE setMsg(String msg) {
                this.msg = msg;
                return this;
            }
        }

        /**
         * 快递状态
         */
        public static List<NameValue> expressStatusToList() {
            if (!EXPRESS_STATUS_LIST.isEmpty()) {
                return EXPRESS_STATUS_LIST;
            }
            EXPRESS_STATUS[] values = EXPRESS_STATUS.values();
            for (int i = 0; i < values.length; i++) {
                EXPRESS_STATUS value = values[i];
                EXPRESS_STATUS_LIST.add(new NameValue(value.getMsg(), value.name()));
            }
            return EXPRESS_STATUS_LIST;
        }

        public enum EXPRESS_STATUS {
            NO_SEND("待发货"), DOING("运输中"), SEND_TO("已送达"), CANCEL("取消");
            @JsonValue
            private String msg;

            public String getMsg() {
                return msg;
            }

            public EXPRESS_STATUS setMsg(String msg) {
                this.msg = msg;
                return this;
            }

            EXPRESS_STATUS(String msg) {
                this.msg = msg;
            }
        }
    }

    class Images {
        public enum TYPE {
            TUODAN("脱单照片"), SWIPER("轮播图"), CONTENT_IMG("商品内容图片"), ARTICLE("文章"), PRODUCT("二手货物");
            private String msg;

            TYPE(String msg) {
                this.msg = msg;
            }

            public String getMsg() {
                return msg;
            }

            public TYPE setMsg(String msg) {
                this.msg = msg;
                return this;
            }
        }
    }

    class Minio {
        public enum Bucket {
            article, avatar, idCard, goods, qrcode, product, swiper, giftstudent, TuoDan;
        }

        public enum ContentType {
            IMG("image/jpeg"), MP3("audio/mp3"), MP4("video/mpeg4");
            private String contentType;

            ContentType(String contentType) {
                this.contentType = contentType;
            }

            public String getContentType() {
                return contentType;
            }

            public ContentType setContentType(String contentType) {
                this.contentType = contentType;
                return this;
            }
        }
    }

    class Customer {
        public enum Status {
            NORMAL(0), NO_NORMAL(1);
            private Integer code;

            Status(Integer code) {
                this.code = code;
            }

            public Integer getCode() {
                return code;
            }

            public Status setCode(Integer code) {
                this.code = code;
                return this;
            }
        }

    }

    class Product {
        public enum STATUS {
            NORMAL, SOLD
        }
    }

    class Message {
        public enum TYPE {
            ARTICLE_AGREE, TASK_NOTICE, PACKAGES_NOTICE, COMMENT_NOTICE
        }
    }

    class UsedRemark {
        public enum TYPE {
            PACKAGE_ADDR_REC, PACKAGE_ADDR_TAKE, PACKAGE_REMARK;
        }
    }
}
